#include <queue>

using namespace std;

int culculatefn(int max,int k){
    queue<int> queue1;
    int temp;
    queue1.push(0);
    for (int i=0;i<k-1;i++) queue1.push(1);
    int sum=k-1;
    int tempsum;
    while (sum<=max){
        temp=queue1.front();
        queue1.pop();
        queue1.push(sum);
        tempsum=sum;
        sum+=sum;
        sum-=temp;
    }
    return tempsum;
}